﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JXT.PrimaryKey.Batman.Collections;
using JXT.PrimaryKey.Batman.Domain.Services;
using JXT.PrimaryKey.Batman.Domain.Quotation.Models;
using JXT.PrimaryKey.Batman.Domain.Specifications;

namespace JXT.PrimaryKey.Batman.Domain.Quotation.Services
{
    /// <summary>
    /// 交易数据服务
    /// </summary>
    public interface IRealTimeQuoteService : ICachedService
    {
        /// <summary>
        /// 保存实时交易数据
        /// </summary>
        /// <param name="entity">实时数据</param>
        void Add(RealTimeQuote entity);

        /// <summary>
        /// 批量写入实时交易数据
        /// </summary>
        /// <param name="list">数据集合</param>
        void Add(IEnumerable<RealTimeQuote> list);

        /// <summary>
        /// 保存实时交易数据至缓存服务器
        /// </summary>
        /// <param name="entity">实时数据</param>
        void AddCache(RealTimeQuote entity);

        /// <summary>
        /// 将榜单数据写入系统缓存
        /// </summary>
        /// <param name="source">榜单数据</param>
        /// <param name="securitiesType">股票类型</param>
        /// <param name="marketType">市场类型</param>
        /// <param name="rankType">榜单类型</param>
        void AddRank(IEnumerable<RealTimeQuote> source, MarketType marketType,SecuritiesType securitesType, MarketRankType rankType);

        /// <summary>
        /// 获取指定股票的当前交易数据
        /// </summary>
        /// <param name="code">股票代码</param>
        /// <param name="type">交易所类型</param>
        /// <returns>实时交易数据</returns>
        RealTimeQuote GetSingle(string code, MarketType type = MarketType.Unknown);

        /// <summary>
        /// 获取榜单数据
        /// </summary>
        /// <param name="marketType">市场类型</param>
        /// <param name="securitiesType">股票类型</param>
        /// <param name="rankType">榜单类型</param>
        /// <param name="num">数据数量，默认为5</param>
        /// <returns>实时交易数据</returns>
        IEnumerable<RealTimeQuote> GetRankList(MarketType marketType, SecuritiesType securitiesType,MarketRankType rankType, int num = 5);

        /// <summary>
        /// 获取指定股票指定时间段的交易记录
        /// </summary>
        /// <param name="code">股票代码</param>
        /// <param name="type">市场类型</param>
        /// <param name="startTime">开始时间，为空则为当日0时</param>
        /// <param name="endTime">结束时间，为空则取到最新记录为止</param>
        /// <returns>实时数据集合</returns>
        IEnumerable<RealTimeQuote> GetList(string code, MarketType type = MarketType.Unknown, DateTime? startTime = null, DateTime? endTime = null);


        /// <summary>
        /// 将每天最后的一笔数据写入到mongodb
        /// </summary>
        /// <param name="type"></param>
        /// <param name="dt"></param>
        void AddLastData(MarketType type, DateTime? dt,TimeSortType timesort=TimeSortType.Daily);

        /// <summary>
        /// 设置市场状态
        /// </summary>
        /// <param name="status">市场状态</param>
        void SetMarketStatus(IEnumerable<MarketStatus> status);

        /// <summary>
        /// 获取市场状态信息
        /// </summary>
        /// <returns>市场状态</returns>
        IEnumerable<MarketStatus> GetMarketStatus();
    }
}
